// 一个完整的模块
import { getUserInfo2 } from "@/request/api/user"
// 1.状态变量
const state = {
  name: 'xiaoming',
  id: -1,
  userInfo:{},
  menuList:[],
  title:"",
  hotList:[],
  count:0
}

// 2.同步方法 修改state变量
const mutations = {
	SET_MENULIST: (state, data = []) => {
	  state.menuList = data
	},
	SET_HOTLIST: (state, data = []) => {
	  state.hotList = data
	},
  SET_TITLE: (state, data = '') => {
    state.title = data
  },
  SET_NAME: (state, data = '') => {
    state.name = data
  },
  SET_ID: (state, data = Number) => {
    state.id = data
  },
  SET_COUNT: (state, data = Number) => {
    state.count = data
  },
   // 3.通过直接actions调接口存值
   SET_USERINFO: (state, data = []) => {
    state.userInfo = data
  }
}

// 3.异步调用mutations内的修改state的方法
const actions = {
  changeId({ commit }, data = Number) {
    commit('SET_ID', data)
  },
  getInfo({ commit }, data = Number) {
    getUserInfo2(data).then(res => {
      commit('SET_USERINFO', res.data.result)
    })
  },
  alreadyInfo({ commit }, data = Number) {
    commit('SET_USERINFO', data)
  }
}

// 4.变量暴露出去
export default {
  namespaced: true,
  state,
  mutations,
  actions
}


